import React,{Component} from "react";
import {Link} from 'react-router-dom';
import $ from 'jquery';
import history from '../history';
import { Input, Icon,Button,Form,message } from 'antd';
import 'antd/dist/antd.css';
import './Reset.css';
const FormItem = Form.Item;

class Reset extends Component{
    constructor(props){
        super(props);
        this.state = {

        }
    };
    check = () => {
        this.props.form.validateFields(
          (err,values) => {
            if (!err) {
                $.ajax({
                  type: "POST",
                  url: "http://localhost:8008/user/updatebn",
                  dataType: "json",
                  contentType:"application/json",
                  data:JSON.stringify({'userName':values.userName,'passwd':values.passwd}),
                  success:function(){
                    message.success(values.userName+"修改成功！");
                    history.push("/Login");
                  },error:function() {
                    message.error("修改失败,请检查后台接口！");
                  }
                })
            }
          },
        );
      }

    ComponentDidMount(){

    }


    render(){
        const { getFieldDecorator } = this.props.form;
        return(
            <div className="big">
              <Form onSubmit={this.handleSubmit} className="login-form">
                <div className="font">重 置 密 码</div>
              <FormItem>
                {getFieldDecorator('userName', {
                  rules: [{ required: true, message: '请输入用户名!' }],
                })(
                  <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="用户名" autocomplete="off" />
                )}
              </FormItem>
              <FormItem>
                {getFieldDecorator('passwd', {
                  rules: [{ required: true, message: '请输入密码!' }],
                })(
                  <Input.Password prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="passwd" placeholder="请输入密码" autocomplete="off"/>
                )}
              </FormItem>
              <div className="cancel">
              <div className="change">
                <Button type="primary" htmlType="submit" onClick={this.check.bind(this)}>修改密码</Button>
              </div>
              <div className="change1">
              <Link to="/Login">
                <Button type="primary" htmlType="submit" >取消</Button>
              </Link>
              </div>
              </div>
              
            
              </Form>
            </div>
        )
      }
};

const WrappedNormalLoginForm = Form.create()(Reset);
export default WrappedNormalLoginForm;